package com.darren.archive.utils.fastjson;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import com.alibaba.fastjson.serializer.SerializeWriter;
import com.darren.archive.enums.IBaseEnum;

import java.lang.reflect.Type;

public class FastJsonEnumSerializer implements ObjectSerializer {

    @Override
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) {
        SerializeWriter out = serializer.out;
        if (object instanceof IBaseEnum) {
            IBaseEnum baseEnum = (IBaseEnum) object;
            out.write("\""+baseEnum.getText()+"\"");
        } else {
            out.writeEnum((Enum<?>) object);
        }
    }

}